package controller;

import java.text.SimpleDateFormat;
import java.util.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import common.PageReturn;
import common.SensitivewordFilter;
import jdk.nashorn.internal.runtime.ECMAException;
import jdk.nashorn.internal.runtime.Undefined;
import org.apache.ibatis.scripting.xmltags.ForEachSqlNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import common.FileManager;
import pojo.*;
import service.*;

@Controller
@RequestMapping("essay")
public class EssayController {

    @Autowired
    private EssayServiceI eServiceI;
    @Autowired
    private PORTServiceI pServiceI;
    @Autowired
    private CommentServiceI commentServiceI;
    @Autowired
    private EssayAndUserAndCommentServiceI essayAndUserAndCommentServiceI;
    @Autowired
    private EssayFileServiceI essayFileServiceI;
    @Autowired
    private EssayFileServiceI eFileServiceI;
    @Autowired
    private CollectionServiceI cServiceI;
    @Autowired
    private AttentionServiceI aServiceI;
    @Autowired
    private UserServiceI userServiceI;
    @Autowired
    private ObtainServiceI obtainServiceI;
    @Autowired
    private SignServiceI signServiceI;
    @Autowired
    private MessageServiceI messageServiceI;
    @Autowired
    private ManagerMessageServiceI managerMessageServiceI;

    private static Integer LimitNumber = 10;

    /**
     * @Title: eassyadd
     * @Description: 发表文章跳转页
     * @param: String @throws
     */
    @RequestMapping("eassyadd")
    public String eassyadd() {
        return "/community/jsp/essay/essayadd";
    }

    /**
     * @Title: eassydetail
     * @Description:显示文章详细内容
     * @param: @paramrequest
     * @param: @param essay
     * @param: @param mView
     * @param: @return
     * @return: ModelAndView @throws
     */

    @RequestMapping("essaydetail")
    public ModelAndView eassydetail(HttpServletRequest request, EssayAndUser eUser, ModelAndView mView) {
        try {
            Integer essayId = Integer.valueOf(request.getParameter("essayId")).intValue();
            /****************更新文章阅读量**********************/
            eUser = eServiceI.ShowEssayDetail(essayId);
            if ("downLoadEssay".equals(eUser.getCategory())) {
                /****************************更新文章阅读量*********************************************/
                Essay essay2 = new Essay();
                essay2.setEssayId(essayId);
                Integer i = eUser.getReadNumber();
                eUser = null;
                i++;
                essay2.setReadNumber(i);
                eServiceI.UpdateEssayPtcvr(essay2);//更新文章阅读数据
                /******************************************************************************************/
                eUser = eServiceI.ShowEssayDetail(essayId);// 获取文章的详细数据
                List<EssayFile> essayFiles = essayFileServiceI.FindEssayFile(essayId);
                List<EssayAndUserAndComment> list = essayAndUserAndCommentServiceI.FindAllCommentByEssayId(essayId);
                mView.addObject("essay", eUser);
                mView.addObject("commentlist", list);
                mView.addObject("essayFiles", essayFiles);
                mView.setViewName("/community/jsp/essay/download");
            } else {
                /****************************更新文章阅读量*********************************************/
                Essay essay2 = new Essay();
                essay2.setEssayId(essayId);
                Integer i = eUser.getReadNumber();
                eUser = null;
                i++;
                essay2.setReadNumber(i);
                eServiceI.UpdateEssayPtcvr(essay2);//更新文章阅读数据
                /******************************************************************************************/
                eUser = eServiceI.ShowEssayDetail(essayId);// 获取文章的详细数据
                List<EssayAndUserAndComment> list = essayAndUserAndCommentServiceI.FindAllCommentByEssayId(essayId);
                String fileLabel = "video";
                List<EssayFile> filelist = eFileServiceI.FindVideo(essayId, fileLabel);
                mView.addObject("essay", eUser);
                mView.addObject("commentlist", list);
                mView.addObject("filelist", filelist);
                mView.setViewName("/community/jsp/essay/essaydetail");
            }
            return mView;
        } catch (Exception e) {
            mView.setViewName("/community/jsp/other/500");
            return mView;
        }

    }

        /**
        　　* @param request  eUser  mView
        　　* @return ModelAndView
        　　* @author：千夜
        　　* @date 2019/6/3 15:24
         　 * @description: TODO
        　　*/

    @RequestMapping("auditingEssay")
    public ModelAndView auditingEssay(HttpServletRequest request, EssayAndUser eUser, ModelAndView mView) {
        Integer essayId = Integer.valueOf(request.getParameter("essayId")).intValue();
        String messageid = request.getParameter("messageId");
        Integer messageId = 0;
        if (messageid != null && !"undefined".equals(messageid)) {
            messageId = Integer.valueOf(request.getParameter("messageId")).intValue();
        }
        eUser = eServiceI.ShowEssayDetail(essayId);
        if(eUser==null){//文章已经被发布者删除
            mView.setViewName("/community/jsp/other/nonetips");
        }else{
            if ("downLoadEssay".equals(eUser.getCategory())) {
                eUser = eServiceI.ShowEssayDetail(essayId);// 获取文章的详细数据
                List<EssayFile> essayFiles = essayFileServiceI.FindEssayFile(essayId);
                mView.addObject("essay", eUser);
                mView.addObject("messageId", messageId);
                mView.addObject("essayFiles", essayFiles);
                mView.setViewName("/community/jsp/manager/auditingEssay");
            } else {
                eUser = eServiceI.ShowEssayDetail(essayId);// 获取文章的详细数据
                String fileLabel = "video";
                List<EssayFile> filelist = eFileServiceI.FindVideo(essayId, fileLabel);
                mView.addObject("essay", eUser);
                mView.addObject("messageId", messageId);
                mView.addObject("filelist", filelist);
                mView.setViewName("/community/jsp/manager/auditingEssay");
            }
        }
        return mView;
    }

    /**
     * @throws
     * @Title: essayread
     * @Description: 登录/未登录首页显示文章/默认根据时间排序
     * @param: @paramrequest
     * @param: @return
     * @return: ModelAndView
     */
    @RequestMapping("essayread")
    public ModelAndView essayread(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView();
        User user = (User) session.getAttribute("user");
        /**************************分页获取相关参数************************************/
        String Page = request.getParameter("currentPage");
        Integer currentPage;
        if (Page != null) {
            currentPage = Integer.valueOf(Page).intValue();
        } else {
            currentPage = 1;
        }
        Page page = new Page();
        page.setLimitNumber(LimitNumber);
        page.setCurrentPage(currentPage);
        PageReturn pageReturn = new PageReturn();
        page = pageReturn.ReturnPage(page);//填充page实体
        Integer locationPage = currentPage;
        modelAndView.addObject("currentPage", locationPage);
        /*************************************************************************/
        if (request.getSession().getAttribute("user") != null) {   // 用户已经登录了
            String permission = "B_self";
            List<EssayAndUser> list = eServiceI.ShowLimitEssayLogin(permission, page);//ֻ显示分页文章数据/已登录的
            int listCount = eServiceI.ShowLimitEssayLoginCount(permission);
            /*******************************根据时间显示最近评论文章**************************************/
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置时间格式
            String startDate = df.format(new Date());
            List<EssayAndUser> commentlist = eServiceI.FindByCommentNumberLimit(startDate, permission);//不显示仅自己可见的文章
            /***********************************************************************/
            /**********************判断用户是否签到********************************/
            Integer userId = user.getUserId();
            Sign sign = signServiceI.SignRecord(userId);//查询是否有签到记录
            if (sign == null) {
                modelAndView.addObject("sign", "no");
            } else {
                String lastSignDate = sign.getSignDate();//获取上一次签到时间
                if (lastSignDate.equals(startDate)) {
                    modelAndView.addObject("sign", "yes");
                } else {
                    modelAndView.addObject("sign", "no");
                }
            }
            /************************判断用户是否有未读消息*****************************/
            boolean havenoread = messageServiceI.HaveNoReadMessage(userId);
            if (havenoread) {
                modelAndView.addObject("havenoread", "1");
            } else {
                modelAndView.addObject("havenoread", "0");
            }
            /********************************************************************/
            modelAndView.addObject("orderby", "date");
            modelAndView.addObject("currentcategory", "ALL");
            modelAndView.addObject("essaylist", list);
            modelAndView.addObject("essayListCount", listCount);
            modelAndView.addObject("commentlist", commentlist);
            modelAndView.setViewName("/community/jsp/user/logindex");
        } else if (request.getSession().getAttribute("user") == null) {   //用户没有登录
            String permission = "B_all";
            List<EssayAndUser> list = eServiceI.ShowLimitEssayLogout(permission, page);//ֻ显示15条文章数据/未登录的
            int listCount = eServiceI.ShowLimitEssayLogoutCount(permission);
            /*******************************根据时间显示最近评论文章**************************************/
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置时间格式
            String startDate = df.format(new Date());
            List<EssayAndUser> commentlist = eServiceI.FindByCommentNumber(startDate, permission);//仅显示所有人可见
            /***********************************************************************/
            modelAndView.addObject("orderby", "date");
            modelAndView.addObject("currentcategory", "ALL");
            modelAndView.addObject("essaylist", list);
            modelAndView.addObject("essayListCount", listCount);
            modelAndView.addObject("commentlist", commentlist);
            modelAndView.setViewName("/community/jsp/user/logindex");
            modelAndView.setViewName("/community/jsp/user/unlogindex");
        }
        return modelAndView;
    }

    @RequestMapping("essayReadByPraise")
    public ModelAndView essayReadByPraise(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView();
        User user = (User) session.getAttribute("user");
        /**************************分页获取相关参数************************************/
        String Page = request.getParameter("currentPage");
        Integer currentPage;
        if (null != Page) {
            currentPage = Integer.valueOf(Page).intValue();
        } else {
            currentPage = 1;
        }
        Page page = new Page();
        page.setLimitNumber(LimitNumber);
        page.setCurrentPage(currentPage);
        PageReturn pageReturn = new PageReturn();
        page = pageReturn.ReturnPage(page);//填充page实体
        Integer locationPage = currentPage;
        modelAndView.addObject("currentPage", locationPage);
        /*************************************************************************/
        if (request.getSession().getAttribute("user") != null) {   // 用户已经登录了
            String permission = "B_self";
            List<EssayAndUser> list = eServiceI.FindEssayByPraiseLogin(page);//ֻ显示15条文章数据/已登录的/根据点赞排序
            int listCount = eServiceI.FindEssayByPraiseLoginCount();
            /*******************************根据时间显示最近评论文章**************************************/
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置时间格式
            String startDate = df.format(new Date());
            List<EssayAndUser> commentlist = eServiceI.FindByCommentNumberLimit(startDate, permission);//不显示仅自己可见的文章
            /***********************************************************************/
            /**********************判断用户是否签到********************************/
            Integer userId = user.getUserId();
            Sign sign = signServiceI.SignRecord(userId);//查询是否有签到记录
            if (sign == null) {
                modelAndView.addObject("sign", "no");
            } else {
                String lastSignDate = sign.getSignDate();//获取上一次签到时间
                if (lastSignDate.equals(startDate)) {
                    modelAndView.addObject("sign", "yes");
                } else {
                    modelAndView.addObject("sign", "no");
                }
            }
            /************************判断用户是否有未读消息*****************************/
            boolean havenoread = messageServiceI.HaveNoReadMessage(userId);
            if (havenoread) {
                modelAndView.addObject("havenoread", "1");
            } else {
                modelAndView.addObject("havenoread", "0");
            }
            /********************************************************************/
            modelAndView.addObject("orderby", "praise");
            modelAndView.addObject("currentcategory", "ALL");
            modelAndView.addObject("essaylist", list);
            modelAndView.addObject("essayListCount", listCount);
            modelAndView.addObject("commentlist", commentlist);
            modelAndView.setViewName("/community/jsp/user/logindex");
        } else if (request.getSession().getAttribute("user") == null) {   //用户没有登录
            String permission = "B_all";
            List<EssayAndUser> list = eServiceI.FindEssayByPraiseLogout(page);//ֻ显示15条文章数据/未登录的/根据点赞排序
            int listCount = eServiceI.FindEssayByPraiseLogoutCount();
            /*******************************根据时间显示最近评论文章**************************************/
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置时间格式
            String startDate = df.format(new Date());
            List<EssayAndUser> commentlist = eServiceI.FindByCommentNumber(startDate, permission);//仅显示所有人可见
            /***********************************************************************/
            modelAndView.addObject("orderby", "praise");
            modelAndView.addObject("currentcategory", "ALL");
            modelAndView.addObject("essaylist", list);
            modelAndView.addObject("essayListCount", listCount);
            modelAndView.addObject("commentlist", commentlist);
            modelAndView.setViewName("/community/jsp/user/logindex");
            modelAndView.setViewName("/community/jsp/user/unlogindex");
        }
        return modelAndView;
    }

    /**
     * @throws
     * @Title: ptcvactive
     * @Description: 点赞踩操作
     * @param: @param modelAndView
     * @param: @param request
     * @param: @return
     * @return: ModelAndView
     */
    @RequestMapping("ptcvactive")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)//添加事务管理
    public String ptcvactive(HttpServletRequest request) {
        String flag = request.getParameter("flag");
        Integer essayId = Integer.valueOf(request.getParameter("essayId")).intValue();
        Integer userId = 0;
        try {
            User user = (User) request.getSession().getAttribute("user");
            userId = user.getUserId();
        } catch (Exception e) {
            return "redirect:/user/logout.do";
        }
        if ("praise".equals(flag)) {  //点赞事件
            PORTV port = pServiceI.FindPORT(essayId, userId);
            if (port == null) {//之前没有数据，插入
                /*******************更新点赞数量*************************/
                EssayAndUser eAndUser = eServiceI.ShowEssayDetail(essayId);//查询文章的相关信息
                System.out.println(eAndUser.getUser());
                int number = eAndUser.getLikeNumber();
                number++;//更新点赞数量
                Essay essay2 = new Essay();
                essay2.setEssayId(essayId);
                essay2.setLikeNumber(number);
                int i = eServiceI.UpdateEssayPtcvr(essay2);//更新
                /*******************更新portv表***********************/
                int praise1 = 1;
                int tread1 = 0;
                int validity = 0;
                PORTV Praise = new PORTV();
                Praise.setEssayId(essayId);
                Praise.setUserId(userId);
                Praise.setPraise(praise1);
                Praise.setTread(tread1);
                Praise.setValidity(validity);
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置时间格式
                String ptvdate = df.format(new Date());
                Praise.setPtvdate(ptvdate);
                int j = pServiceI.PraiseORTreadAction(Praise);//更新表
                if (i > 0 && j > 0) {//两个表都更新成功
                    System.out.println(eAndUser.getUser());
                    /*********************进行消息表的插入数据*****************************/
                    Integer senduser = eAndUser.getUser().getUserId();
                    Integer receiveuser = userId;
                    Integer operateflag = 0;
                    try {
                        messageServiceI.MakeMessage(senduser, receiveuser, operateflag, essayId);
                    } catch (Exception e) {
                        e.printStackTrace();
                        return "false";
                    }
                    /*******************************消息表更新完成******************************************************/
                    return "praise";
                } else {
                    return "false";
                }
            } else {//之前有数据，判断更新
                int praise = port.getPraise();
                int tread = port.getTread();
                if (praise == 1 && tread == 0) {//
                    Integer validity = port.getValidity();
                    Integer portId = port.getPortId();
                    int j = 0, k = 0;
                    if (validity == 0) {
                        j = pServiceI.unPraiseORunTreadAction(portId);//没有贡献过真实度
                    } else if (validity == 1) {//有这条数据，贡献过真实度，取消点赞
                        PORTV portv = new PORTV();
                        portv.setPortId(portId);
                        int praise1 = 0;
                        portv.setPraise(praise1);
                        k = pServiceI.UpdatePORTV(portv);
                    }
                    /******************更新点赞数，文章表*************************/
                    EssayAndUser eAndUser = eServiceI.ShowEssayDetail(essayId);//获取文章相关信息
                    int number = eAndUser.getLikeNumber();
                    if (number > 0) {
                        number--;
                    }
                    Essay essay2 = new Essay();
                    essay2.setEssayId(essayId);
                    essay2.setLikeNumber(number);
                    int i = eServiceI.UpdateEssayPtcvr(essay2);//更新，取消点赞
                    if (i > 0 && j > 0 || i > 0 && k > 0) {
                        return "unpraise";
                    } else {
                        return "false";
                    }
                } else if (praise == 0 && tread == 1) {//已经点赞过
                    return "alreadytread";
                } else if (praise == 0 && tread == 0) {//没有点赞过
                    /*******************进行表的更新*************************/
                    EssayAndUser eAndUser = eServiceI.ShowEssayDetail(essayId);//获取文章的信息
                    int number = eAndUser.getLikeNumber();
                    number++;//更新点赞数量
                    Essay essay2 = new Essay();
                    essay2.setEssayId(essayId);
                    essay2.setLikeNumber(number);
                    int i = eServiceI.UpdateEssayPtcvr(essay2);//更新
                    /*******************更新portv表***********************/
                    int praise1 = 1;
                    int tread1 = 0;
                    Integer portvId = port.getPortId();
                    PORTV Praise = new PORTV();
                    Praise.setPortId(portvId);
                    Praise.setEssayId(essayId);
                    Praise.setUserId(userId);
                    Praise.setPraise(praise1);
                    Praise.setTread(tread1);
                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String ptvdate = df.format(new Date());
                    Praise.setPtvdate(ptvdate);
                    int j = pServiceI.UpdatePORTV(Praise);//更新
                    if (i > 0 && j > 0) {
                        /*********************进行消息表的插入数据*****************************/
                        Integer senduser = eAndUser.getUser().getUserId();
                        Integer receiveuser = userId;
                        Integer operateflag = 0;
                        try {
                            messageServiceI.MakeMessage(senduser, receiveuser, operateflag, essayId);
                        } catch (Exception e) {
                            e.printStackTrace();
                            return "false";
                        }
                        /*******************************消息表更新完成******************************************************/
                        return "praise";
                    } else {
                        return "false";
                    }
                }
            }

        } else if ("tread".equals(flag)) {
            PORTV port = pServiceI.FindPORT(essayId, userId);
            if (port == null) {//表内有相关数据
                /*******************更新被踩数量*************************/
                EssayAndUser eAndUser = eServiceI.ShowEssayDetail(essayId);//查询文章表内之前的被踩数量
                int number = eAndUser.getTreadNumber();
                number++;
                Essay essay2 = new Essay();
                essay2.setEssayId(essayId);
                essay2.setTreadNumber(number);
                int i = eServiceI.UpdateEssayPtcvr(essay2);//�������±�
                /*******************更新portv表***********************/
                PORTV Tread = new PORTV();
                int praise2 = 0;
                int tread2 = 1;
                int validity2 = 0;
                Tread.setEssayId(essayId);
                Tread.setUserId(userId);
                Tread.setPraise(praise2);
                Tread.setTread(tread2);
                Tread.setValidity(validity2);
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置时间格式
                String ptvdate = df.format(new Date());// new Date()获取当前时间戳
                Tread.setPtvdate(ptvdate);
                int j = pServiceI.PraiseORTreadAction(Tread);//更新
                if (i > 0 && j > 0) {
                    return "tread";
                } else {
                    return "false";
                }
            } else {
                int praise = port.getPraise();
                int tread = port.getTread();
                if (tread == 1 && praise == 0) {//踩过但是未赞过
                    /*******************更新被踩数量*************************/
                    EssayAndUser eAndUser = eServiceI.ShowEssayDetail(essayId);
                    int number = eAndUser.getTreadNumber();
                    if (number > 0) {
                        number--;
                    }
                    Essay essay2 = new Essay();
                    essay2.setEssayId(essayId);
                    essay2.setTreadNumber(number);
                    int i = eServiceI.UpdateEssayPtcvr(essay2);//更新
                    /********************PORTV表的更新***********************************/
                    int validity = port.getValidity();
                    Integer portId = port.getPortId();
                    PORTV portv = new PORTV();
                    int j = 0, k = 0;
                    if (validity == 0) {
                        j = pServiceI.unPraiseORunTreadAction(portId);//之前踩过，取消踩
                    } else if (validity == 1) {
                        portv.setPortId(portId);
                        int tread1 = 0;
                        portv.setTread(tread1);
                        k = pServiceI.UpdatePORTV(portv);
                    }
                    if (i > 0 && j > 0 || i > 0 && k > 0) {
                        return "untread";
                    } else {
                        return "false";
                    }
                } else if (tread == 0 && praise == 1) {//�޹�
                    return "alreadypraise";
                } else if (tread == 0 && praise == 0) {
                    /*******************踩***********************/
                    EssayAndUser eAndUser = eServiceI.ShowEssayDetail(essayId);//获取相关数据
                    int number = eAndUser.getTreadNumber();
                    number++;
                    Essay essay2 = new Essay();
                    essay2.setEssayId(essayId);
                    essay2.setTreadNumber(number);
                    int i = eServiceI.UpdateEssayPtcvr(essay2);//更新
                    /*******************更新portv表***********************/
                    PORTV Tread = new PORTV();
                    int praise2 = 0;
                    int tread2 = 1;
                    Integer portvId = port.getPortId();
                    Tread.setPortId(portvId);
                    Tread.setEssayId(essayId);
                    Tread.setUserId(userId);
                    Tread.setPraise(praise2);
                    Tread.setTread(tread2);
                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置时间格式
                    String ptvdate = df.format(new Date());//
                    Tread.setPtvdate(ptvdate);
                    int j = pServiceI.UpdatePORTV(Tread);//更新
                    if (i > 0 && j > 0) {
                        return "tread";
                    } else {
                        return "false";
                    }
                }
            }

        } else if ("validity".equals(flag)) {
            PORTV portv = pServiceI.FindPORT(essayId, userId);
            Integer value = Integer.valueOf(request.getParameter("value")).intValue();
            User user = (User) request.getSession().getAttribute("user");
            int grade = user.getGrade();
            double g = (double) grade;
            if (portv == null) {//贡献真实度
                /******************更新文章表�*************************/
                EssayAndUser eAndUser = eServiceI.ShowEssayDetail(essayId);
                double nowvalidity = eAndUser.getValidity();
                double validity = (g / 100) * value + nowvalidity;
                Essay essay2 = new Essay();
                essay2.setEssayId(essayId);
                essay2.setValidity(validity);
                int i = eServiceI.UpdateEssayPtcvr(essay2);//�������±�
                /*********************更新portv表***************************/
                int val = 1;
                PORTV Validity = new PORTV();
                int praise = 0;
                int tread = 0;
                Validity.setEssayId(essayId);
                Validity.setUserId(userId);
                Validity.setPraise(praise);
                Validity.setTread(tread);
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置时间格式
                String ptvdate = df.format(new Date());
                Validity.setPtvdate(ptvdate);
                Validity.setValidity(val);
                int j = pServiceI.PraiseORTreadAction(Validity);
                if (i > 0 && j > 0) {
                    return "validity";
                } else {
                    return "false";
                }
            } else if (portv != null) {
                if (portv.getValidity() == 1) {
                    return "alreadyvalidity";
                } else if (portv.getValidity() == 0) {//���й��޻��߲Ȳ���������δ������ʵ�ȵĹ���
                    PORTV port = pServiceI.FindPORT(essayId, userId);
                    /*******************更新文章表*************************/
                    EssayAndUser eAndUser = eServiceI.ShowEssayDetail(essayId);
                    double nowvalidity = eAndUser.getValidity();
                    double validity = (g / 100) * value + nowvalidity;
                    Essay essay2 = new Essay();
                    essay2.setEssayId(essayId);
                    essay2.setValidity(validity);
                    int i = eServiceI.UpdateEssayPtcvr(essay2);//更新真实度
                    /**********************更新portv表***************************/
                    int val = 1;
                    PORTV Validity = new PORTV();
                    Integer portvId = port.getPortId();
                    Validity.setPortId(portvId);
                    Validity.setEssayId(essayId);
                    Validity.setUserId(userId);
                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//
                    String ptvdate = df.format(new Date());
                    Validity.setPtvdate(ptvdate);
                    Validity.setValidity(val);
                    int j = pServiceI.UpdatePORTV(Validity);
                    if (i > 0 && j > 0) {
                        return "validity";
                    } else {
                        return "false";
                    }
                }
            }
        }
        return flag;
    }

    /**
     * @throws Exception
     * @throws
     * @Title: essaypublish
     * @Description: 文章发表，带文件上传
     * @param: @param request
     * @param: @param essay
     * @param: @return
     * @return: String
     */

    @RequestMapping("essaypublish")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public String eessaypublish(HttpServletRequest request, Essay essay, RedirectAttributes redirectAttributes, HttpSession session) throws Exception {
        User user = (User) request.getSession().getAttribute("user");
        if (user == null) {
            return "unlogin";
        }
        Integer userId = user.getUserId();
        String label = request.getParameter("label");
        String category = request.getParameter("category");
        String title = request.getParameter("title");
        String content = request.getParameter("content");
        Integer integration = null;
        if (request.getParameter("integration") != null) {
            integration = Integer.valueOf(request.getParameter("integration")).intValue();
        }
        String permission = request.getParameter("permission");
        int commentNumber = 0;
        int likeNumber = 0;
        int readNumber = 0;
        int treadNumber = 0;
        double validity = 0;
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置时间格式
        String publishDate = df.format(new Date());
        essay.setUserId(userId);
        essay.setTitle(title);
        essay.setDescription(content);
        essay.setCategory(category);
        essay.setLabel(label);
        essay.setPermission(permission);
        essay.setCommentNumber(commentNumber);
        essay.setLikeNumber(likeNumber);
        essay.setReadNumber(readNumber);
        essay.setTreadNumber(treadNumber);
        essay.setValidity(validity);
        essay.setIntegration(integration);
        essay.setPublishDate(publishDate);
        Integer essayId = 0;
        try {
            eServiceI.ReturnEssayId(essay);//插入文章/并返回插入后的自增ID
            essayId = essay.getEssayId();//获取ID
            if (session.getAttribute("EssayFile") != null) {
                List<EssayFile> list = (List<EssayFile>) session.getAttribute("EssayFile");//获取session里面保存的文件路径数据
                /****************************************上传文件获得积分****************************************************/
                if ("downLoadEssay".equals(category)) {//判断是否为下载贴/下载帖获得积分/权限保存，自己可随时下载
                    int number = list.size();
                    int tempIntegration = user.getIntegration();
                    tempIntegration = tempIntegration + number * 3;
                    User user2 = new User();
                    user2.setUserId(userId);
                    user2.setIntegration(tempIntegration);
                    userServiceI.CompleteUserInformation(user2);
                    /*******更新权限*********/
                    Obtain obtain = new Obtain();
                    obtain.setEssayId(essayId);
                    obtain.setUserId(userId);
                    obtainServiceI.InsertObtain(obtain);
                    /*******************************************************************************************/
                }
                /*****************文章文件插入************************************/
                for (EssayFile essayFile : list) {
                    essayFile.setEssayId(essayId);
                    essayFileServiceI.uploadFile(essayFile);//插入表中
                }
                /****************************************************/
                session.removeAttribute("EssayFile");
                User user3 = userServiceI.FindUserById(userId);
                session.setAttribute("user", user3);//重新注入session
            }
            /***************************检测敏感词********************************************/
            SensitivewordFilter sensitivewordFilter = new SensitivewordFilter();
            String string = title + content;
            Set<String> set = sensitivewordFilter.getSensitiveWord(string, 1);
            String sensitiveWords = "";
            for (String s : set) {
                sensitiveWords += "/" + s;
            }
            if (set.size() > 0) {//如果包含敏感词，生成消息通知管理员
                ManagerMessage managerMessage = new ManagerMessage();
                managerMessage.setEssayId(essayId);//注入文章id
                managerMessage.setUserId(userId);//注入发布者id
                managerMessage.setSensitiveWords(sensitiveWords);//注入敏感词
                managerMessageServiceI.CreatMessage(managerMessage);
            }
            /**********************查询被关注列表*********************************/
            List<Integer> list = userServiceI.SelectAttention(userId);
            try {
                for (Integer integer : list) {
                    userServiceI.MakeAttentionMessage(integer, user.getUserName(), essay.getTitle(), publishDate);//发送相关消息
                }
            } catch (Exception e) {
                e.printStackTrace();
                return "false";
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "false";
        }
        ;
        return "success";
    }

    /**
     * @throws
     * @Title: essayreadbyuser
     * @Description:获取已知用户发表的文章
     * @param: @param request
     * @param: @param modelAndView
     * @param: @return
     * @return: ModelAndView
     */

    @RequestMapping("essayreadbyuser")
    public ModelAndView essayreadbyuser(HttpServletRequest request, ModelAndView modelAndView) {
        User user = (User) request.getSession().getAttribute("user");
        /**************************分页获取相关参数************************************/
        String Page = request.getParameter("PcurrentPage");
        Integer currentPage;
        if (null != Page) {
            currentPage = Integer.valueOf(Page).intValue();
        } else {
            currentPage = 1;
        }
        pojo.Page page = new Page();
        page.setLimitNumber(LimitNumber);
        page.setCurrentPage(currentPage);
        System.out.println(currentPage);
        PageReturn pageReturn = new PageReturn();
        page = pageReturn.ReturnPage(page);//填充page实体
        Integer locationPage = currentPage;
        modelAndView.addObject("PcurrentPage", locationPage);
        /*************************************************************************/
        /**************************分页获取相关参数************************************/
        String Page1 = request.getParameter("CcurrentPage");
        Integer currentPage1;
        if (null != Page1) {
            currentPage1 = Integer.valueOf(Page).intValue();
        } else {
            currentPage1 = 1;
        }
        pojo.Page page1 = new Page();
        page1.setLimitNumber(LimitNumber);
        page1.setCurrentPage(currentPage1);
        PageReturn pageReturn1 = new PageReturn();
        page1 = pageReturn.ReturnPage(page1);//填充page实体
        Integer locationPage1 = currentPage1;
        modelAndView.addObject("CcurrentPage", locationPage1);
        /*************************************************************************/
        /**************************分页获取相关参数************************************/
        String Page2 = request.getParameter("AcurrentPage");
        Integer currentPage2;
        if (null != Page2) {
            currentPage2 = Integer.valueOf(Page).intValue();
        } else {
            currentPage2 = 1;
        }
        pojo.Page page2 = new Page();
        page2.setLimitNumber(LimitNumber);
        page2.setCurrentPage(currentPage2);
        PageReturn pageReturn2 = new PageReturn();
        page2 = pageReturn.ReturnPage(page2);//填充page实体
        Integer locationPage2 = currentPage2;
        modelAndView.addObject("AcurrentPage", locationPage2);
        /*************************************************************************/
        /**************************分页获取相关参数************************************/
        String Page3 = request.getParameter("OcurrentPage");
        Integer currentPage3;
        if (null != Page3) {
            currentPage3 = Integer.valueOf(Page).intValue();
        } else {
            currentPage3 = 1;
        }
        pojo.Page page3 = new Page();
        page3.setLimitNumber(LimitNumber);
        page3.setCurrentPage(currentPage3);
        PageReturn pageReturn3 = new PageReturn();
        page3 = pageReturn.ReturnPage(page3);//填充page实体
        Integer locationPage3 = currentPage3;
        modelAndView.addObject("OcurrentPage", locationPage3);
        /*************************************************************************/
        String whichPage=request.getParameter("whichPage");
        if(whichPage==null||whichPage==""){
            modelAndView.addObject("whichPage","publish");
        }else{
            modelAndView.addObject("whichPage",whichPage);
        }
        if (user != null) {
            Integer userId = user.getUserId();
            /**********************获取发表文章列表**************************/
            List<Essay> essaylist = eServiceI.ShowUsersEssay(userId,page);
            Integer essaylistsize = eServiceI.ShowUsersEssayCount(userId);//发表的文章数量
            /**********************获取收藏文章列表************************************/
            List<Integer> collectionlist = cServiceI.FindEssayId(userId,page1);
            List<Essay> collectionEssayList = new ArrayList<Essay>();
            for (Integer essayId : collectionlist) {
                Essay essay = eServiceI.FindEssay(essayId);
                collectionEssayList.add(essay);
            }
            Integer collectionEssayListSize = cServiceI.FindEssayIdCount(userId);
            /***********************获取关注用户列表*************************************/
            List<Integer> attentionlist = aServiceI.FindAttentionUser(userId,page2);
            List<User> attentionUserList = new ArrayList<User>();
            for (Integer user2 : attentionlist) {
                User user3 = userServiceI.FindUserById(user2);
                attentionUserList.add(user3);
            }
            Integer attentionUserListSize =aServiceI.FindAttentionUserCount(userId);
            /***********************获取我的下载文章刘表*************************************/
            List<Integer> obtainList = obtainServiceI.FindEssay(userId,page3);
            List<Essay> obtainEssayList = new ArrayList<Essay>();
            for (Integer integer : obtainList) {
                Essay essay = eServiceI.FindEssay(integer);
                obtainEssayList.add(essay);
            }
            Integer obtainEssayListSize = obtainServiceI.FindEssayCount(userId);


            modelAndView.addObject("obtainEssayList", obtainEssayList);//下载文章列表
            modelAndView.addObject("obtainEssayListSize", obtainEssayListSize);//下载文章数量
            modelAndView.addObject("collectionEssayList", collectionEssayList);//收藏文章列表
            modelAndView.addObject("collectionEssayListSize", collectionEssayListSize);//收藏文章数量
            modelAndView.addObject("essaylistsize", essaylistsize);//发表文章列表
            modelAndView.addObject("essaylist", essaylist);//发表文章数量
            modelAndView.addObject("attentionUserListSize", attentionUserListSize);//关注用户列表
            modelAndView.addObject("attentionUserList", attentionUserList);//关注用户数量

            modelAndView.setViewName("/community/jsp/user/userindex");
        } else {
            request.getSession().invalidate();
            modelAndView.setViewName("redirect:/essay/essayread.do");
        }
        return modelAndView;
    }

    /**
     * @throws Exception
     * @throws
     * @Title: deleteusersessay
     * @Description: 删除用户发表的文章
     * @param: @param request
     * @param: @return
     * @return: String
     */
    @RequestMapping("deleteessay")
    @ResponseBody
    @Transactional
    public String deleteusersessay(HttpServletRequest request) throws Exception {
        Integer essayId = Integer.valueOf(request.getParameter("essayId")).intValue();
        try {
            eServiceI.DeleteEssay(essayId);//根据文章id删除
            cServiceI.DeleteAllEssay(essayId);//删除收藏相关
            commentServiceI.DeleteAllEssay(essayId);//删除评论相关
            pServiceI.DeleteAllEssay(essayId);//删除赞踩相关
            List<EssayFile> filelist = eFileServiceI.FindEssayFile(essayId);
            essayFileServiceI.RemoveFile(essayId);//删除文章文件
            managerMessageServiceI.DeleteMessage(essayId);//删除管理员消息
            FileManager fileManager = new FileManager("fdfs_client.conf");
            if (filelist != null) {
                for (EssayFile essayFile : filelist) {
                    fileManager.delete_file(essayFile.getFilePath());//删除服务器文件相关
                }
            }
        } catch (Exception e) {
            return "false";
        }
        return "success";

    }

    /**
     * @throws
     * @Title: essayreadselect
     * @Description: 根据类别显示文章，首页的根据类别显示,类别与最新/点赞联合查询
     * @param: @param request
     * @param: @return
     * @return: modelandview
     */
    @RequestMapping("essayreadselect")
    public ModelAndView essayreadselect(HttpServletRequest request, ModelAndView modelAndView, HttpSession session) {
        User user = (User) session.getAttribute("user");
        if (session.getAttribute("user") != null) {    //用户已经登录
            String category = request.getParameter("category");
            String orderby = request.getParameter("orderby");
            String currentpage = request.getParameter("currentPage");
            String permission = "B_self";
            if ("ALL".equals(category)) {
                if ("date".equals(orderby)) {
                    modelAndView.setViewName("redirect:/essay/essayread.do?currentPage=" + currentpage);
                } else if ("praise".equals(orderby)) {
                    modelAndView.setViewName("redirect:/essay/essayReadByPraise.do?currentPage=" + currentpage);
                }
            } else {
                /**************************分页获取相关参数************************************/
                Integer currentPage;
                if (currentpage == null || currentpage == "") {
                    currentPage = 1;
                } else {
                    currentPage = Integer.valueOf(request.getParameter("currentPage")).intValue();
                }
                Page page = new Page();
                page.setLimitNumber(LimitNumber);
                page.setCurrentPage(currentPage);
                PageReturn pageReturn = new PageReturn();
                page = pageReturn.ReturnPage(page);//填充page实体
                Integer locationPage = currentPage;
                modelAndView.addObject("currentPage", locationPage);
                /*************************************************************************/
                if ("date".equals(orderby)) {//按时间排序
                    List<EssayAndUser> list = eServiceI.ShowLimitEssaySelectBself(category, permission, page);
                    int listCount = eServiceI.ShowLimitEssaySelectBselfCount(category, permission);
                    /*******************************根据时间显示最近评论文章**************************************/
                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置时间格式
                    String startDate = df.format(new Date());
                    List<EssayAndUser> commentlist = eServiceI.FindByCommentNumberLimit(startDate, permission);//不显示仅自己可见的文章
                    /***********************************************************************/
                    /**********************判断用户是否签到********************************/
                    Integer userId = user.getUserId();
                    Sign sign = signServiceI.SignRecord(userId);//查询是否有签到记录
                    if (sign == null) {
                        modelAndView.addObject("sign", "no");
                    } else {
                        String lastSignDate = sign.getSignDate();//获取上一次签到时间
                        if (lastSignDate.equals(startDate)) {
                            modelAndView.addObject("sign", "yes");
                        } else {
                            modelAndView.addObject("sign", "no");
                        }
                    }
                    /*****************************************************/
                    modelAndView.addObject("orderby", orderby);
                    modelAndView.addObject("currentcategory", category);
                    modelAndView.addObject("essaylist", list);
                    modelAndView.addObject("essayListCount", listCount);
                    modelAndView.addObject("commentlist", commentlist);
                    modelAndView.setViewName("/community/jsp/user/logindex");
                } else if ("praise".equals(orderby)) {//如果要按点赞量排序
                    List<EssayAndUser> list = eServiceI.FindEssayByCategoryAndPraiseLogin(category, page);
                    int listCount = eServiceI.FindEssayByCategoryAndPraiseLoginCount(category);
                    /*******************************根据时间显示最近评论文章**************************************/
                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置时间格式
                    String startDate = df.format(new Date());
                    List<EssayAndUser> commentlist = eServiceI.FindByCommentNumberLimit(startDate, permission);//不显示仅自己可见的文章
                    /***********************************************************************/
                    /**********************判断用户是否签到********************************/
                    Integer userId = user.getUserId();
                    Sign sign = signServiceI.SignRecord(userId);//查询是否有签到记录
                    if (sign == null) {
                        modelAndView.addObject("sign", "no");
                    } else {
                        String lastSignDate = sign.getSignDate();//获取上一次签到时间
                        if (lastSignDate.equals(startDate)) {
                            modelAndView.addObject("sign", "yes");
                        } else {
                            modelAndView.addObject("sign", "no");
                        }
                    }
                    /*****************************************************/
                    modelAndView.addObject("orderby", orderby);
                    modelAndView.addObject("currentcategory", category);
                    modelAndView.addObject("essaylist", list);
                    modelAndView.addObject("essayListCount", listCount);
                    modelAndView.addObject("commentlist", commentlist);
                    modelAndView.setViewName("/community/jsp/user/logindex");
                }
            }
        } else {               //用户未登录
            String category = request.getParameter("category");
            String orderby = request.getParameter("orderby");
            String currentpage = request.getParameter("currentPage");
            String permission = "B_all";
            if ("ALL".equals(category)) {
                if ("date".equals(orderby)) {
                    modelAndView.setViewName("redirect:/essay/essayread.do?currentPage=" + currentpage);
                } else if ("praise".equals(orderby)) {
                    modelAndView.setViewName("redirect:/essay/essayReadByPraise.do?currentPage=" + currentpage);
                }
            } else {
                /**************************分页获取相关参数************************************/
                Integer currentPage;
                if (currentpage == null || currentpage == "") {
                    currentPage = 1;
                } else {
                    currentPage = Integer.valueOf(request.getParameter("currentPage")).intValue();
                }
                Page page = new Page();
                page.setLimitNumber(LimitNumber);
                page.setCurrentPage(currentPage);
                PageReturn pageReturn = new PageReturn();
                page = pageReturn.ReturnPage(page);//填充page实体
                Integer locationPage = currentPage;
                modelAndView.addObject("currentPage", locationPage);
                /*************************************************************************/
                if ("date".equals(orderby)) {
                    List<EssayAndUser> list = eServiceI.ShowLimitEssaySelect(category, permission, page);//显示所有人可见的文章
                    int listCount = eServiceI.ShowLimitEssaySelectCount(category, permission);
                    /*******************************根据时间显示最近评论文章**************************************/
                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                    Calendar c = Calendar.getInstance();
                    c.setTime(new Date());
                    c.add(Calendar.DATE, -7);
                    Date d = c.getTime();
                    String startDate = format.format(d);
                    List<EssayAndUser> commentlist = eServiceI.FindByCommentNumber(startDate, permission);//仅显示所有人可见
                    /***********************************************************************/
                    modelAndView.addObject("orderby", orderby);
                    modelAndView.addObject("currentcategory", category);
                    modelAndView.addObject("essaylist", list);
                    modelAndView.addObject("essayListCount", listCount);
                    modelAndView.addObject("commentlist", commentlist);
                    modelAndView.setViewName("/community/jsp/user/unlogindex");
                } else if ("praise".equals(orderby)) {
                    List<EssayAndUser> list = eServiceI.FindEssayByCategoryAndPraiseLogout(category, page);//显示所有人可见的文章
                    int listCount = eServiceI.FindEssayByCategoryAndPraiseLogoutCount(category);
                    /*******************************根据时间显示最近评论文章**************************************/
                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                    Calendar c = Calendar.getInstance();
                    c.setTime(new Date());
                    c.add(Calendar.DATE, -7);
                    Date d = c.getTime();
                    String startDate = format.format(d);
                    List<EssayAndUser> commentlist = eServiceI.FindByCommentNumber(startDate, permission);//仅显示所有人可见
                    /***********************************************************************/
                    modelAndView.addObject("orderby", orderby);
                    modelAndView.addObject("currentcategory", category);
                    modelAndView.addObject("essaylist", list);
                    modelAndView.addObject("essayListCount", listCount);
                    modelAndView.addObject("commentlist", commentlist);
                    modelAndView.setViewName("/community/jsp/user/unlogindex");
                }
            }
        }
        return modelAndView;
    }


    /**
     * @throws
     * @Title: canclePublish
     * @Description: TODO(取消发布 ， 这里需要将上传的图片或者视频删除)
     * @param: @param session
     * @param: @return
     * @param: @throws Exception
     * @return: String
     */
    @RequestMapping("canclePublish")
    public String canclePublish(HttpSession session) throws Exception {
        List<EssayFile> list = (List<EssayFile>) session.getAttribute("EssayFile");
        /*System.out.println(list);*/
        FileManager fileManager = new FileManager("fdfs_client.conf");
        if (list != null) {
            for (EssayFile essayFile : list) {
                fileManager.delete_file(essayFile.getFilePath());
            }
            session.removeAttribute("EssayFile");
            return "redirect:/essay/essayread.do";
        } else {
            /*	System.out.println("null");*/
            return "redirect:/essay/essayread.do";
        }
    }


    /**
     * @throws
     * @Title: downLoadValidity
     * @Description: TODO(校验用户是否获取文章下载权限)
     * @param: @param request
     * @param: @param session
     * @param: @return
     * @return: String
     */
    @RequestMapping("downLoadValidity")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public String downLoadValidity(HttpServletRequest request, HttpSession session) {
        User user = (User) session.getAttribute("user");
        Integer essayId = Integer.valueOf(request.getParameter("essayId")).intValue();
        if (user == null) {
            return "unlogin";
        } else {   //用户已经登录，查看是否上传者
            Integer userId = user.getUserId();
            Essay essay = eServiceI.FindEssay(essayId);//查找文章内容
            if (user.getUserId().equals(essay.getUserId())) {//上传者本人
                /*****************查看用户是否拥有权限，此为以防数据库出错**********************/
                boolean bool = obtainServiceI.ObtainOrNot(userId, essayId);
                if (bool) {//已经获取下载权限
                    return "mine";
                } else {//
                    Obtain obtain = new Obtain();
                    obtain.setEssayId(essayId);
                    obtain.setUserId(userId);
                    try {
                        obtainServiceI.InsertObtain(obtain);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
                return "mine";
            } else {//不是上传者本人/查看是否已经拥有权限
                boolean bool = obtainServiceI.ObtainOrNot(userId, essayId);
                if (bool) {//如果已经获得权限
                    return "alreadyObtain";
                } else {//未获得权限
                    int essayIntegration = essay.getIntegration();
                    int userIntegration = user.getIntegration();
/*					System.out.println(essayIntegration);

					System.out.println(userIntegration);*/
                    if (essayIntegration > userIntegration) {//比较文章需要的积分与用户拥有的积分
                        return "shortIntegration";
                    } else {//积分足够
                        int temp = userIntegration - essayIntegration;
                        User user2 = new User();
                        user2.setUserId(user.getUserId());
                        user2.setIntegration(temp);
                        try {
                            userServiceI.CompleteUserInformation(user2);//更新用户积分/减少文章需要的积分
                            int punlisher = eServiceI.FindPublisher(essayId);
                            User user3 = userServiceI.FindUserById(punlisher);
                            int tempIntegration = user3.getIntegration();
                            tempIntegration = tempIntegration + essayIntegration;
                            User user4 = new User();
                            user4.setUserId(user3.getUserId());
                            user4.setIntegration(tempIntegration);
                            userServiceI.CompleteUserInformation(user4);//为发布者增加积分
                            /*****************更新用户下载权限**********************/
                            Obtain obtain = new Obtain();
                            obtain.setEssayId(essayId);
                            obtain.setUserId(userId);
                            obtainServiceI.InsertObtain(obtain);
                        } catch (Exception e) {
                            // TODO: handle exception
                            return "false";
                        }
                        /*********************进行消息表的插入数据*****************************/
                        Integer senduser = userId;
                        Integer receiveuser = essay.getUserId();
                        Integer operateflag = 1;
                        try {
                            messageServiceI.MakeMessage(senduser, receiveuser, operateflag, essayId);
                        } catch (Exception e) {
                            e.printStackTrace();
                            return "false";
                        }
                        /*******************************消息表更新完成******************************************************/
                        return "obtainSuccess";
                    }
                }

            }
        }
    }


    @RequestMapping("downLoad")
    @ResponseBody
    public String downLoad(HttpServletRequest request, HttpSession session) {
        User user = (User) session.getAttribute("user");
        Integer essayId = Integer.valueOf(request.getParameter("essayId")).intValue();
        if (user == null) {
            return "unlogin";
        } else {
            int userId = user.getUserId();
            boolean bool = obtainServiceI.ObtainOrNot(userId, essayId);
            if (bool) {
                return "ok";
            } else
                return "no";
        }
    }

}
